package com.chen;

class MyThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 1000000000; i++){
            System.out.println(getName()+"----"+i);
            if(Thread.currentThread().isInterrupted()){ // main方法执行到 myThread.interrupt(),  次条件就会为true
                System.out.println("线程被打断");
                break;
            }
        }
    }
}

public class DemoInterrupt {
    public static void main(String[] args)  throws Exception{
        MyThread myThread = new MyThread();
        myThread.start();
        Thread.sleep(2000);
        myThread.interrupt();  //本质是设置中断标记为 true是什么意思
    }
}
